package com.jph.simple;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jph.takephoto.model.TResult;

public class SelectPhotoActivity extends SimpleActivity implements SelectPhotoListener {
    private TextView resultTv;
    private ImageView resultImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_photo);

        initView();
    }

    private void initView() {
        resultTv = findViewById(R.id.resultTv);
        resultImg = findViewById(R.id.resultImg);

        findViewById(R.id.photoBtn01).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SelectPhotoActivity.this.onClick("相册", 0, SelectPhotoActivity.this);
            }
        });

        findViewById(R.id.photoBtn02).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SelectPhotoActivity.this.onClick("拍照", 1, SelectPhotoActivity.this);
            }
        });
    }

    @Override
    public void handlerResult(TResult result, int What) {
        if (null == result) {
            return;
        }
        switch (What) {
            case 0:
                Glide.with(this).load(result.getImage().getOriginalPath()).error(R.mipmap.ic_launcher).into(resultImg);
                resultTv.setText(result.getImage().getOriginalPath());
                break;
            case 1:
                Glide.with(this).load(result.getImage().getOriginalPath()).error(R.mipmap.ic_launcher).into(resultImg);
                resultTv.setText(result.getImage().getOriginalPath());
                break;
        }

    }
}
